class Foto < ActiveRecord::Base

  attr_accessible :legenda, :image, :image_updated_at

  belongs_to :vistoria

  has_attached_file :image,
                    :styles => { :small => ["128x96>", :png], :report => "495x265" },
                    # TODO manter proporção VGA (4:3) no report, 480x360 caberia?
                    :url => "#{ActionController::Base.relative_url_root or ''}/system/:class/:hashed_path/:id_:style.:extension",
                    :path => ":rails_root/public/system/:class/:hashed_path/:id_:style.:extension"

  delegate :url, :to => :image, :allow_nil => true

  validates_attachment_presence :image

  validates_presence_of :legenda, :vistoria

  def url_small
    image.url(:small) if image
  end

end
